import sys
import numpy as np
import torch
import torch.nn as nn
import ctypes

sys.path.append("../utils")

from utils import OpRunner, compare, verify_result
import time
import tensorflow as tf

def main():
    func = OpRunner("./build/libop.so", 4, pint_time=True)
    minvalue = 1
    maxvalue = 10
    shape = [1024]
    vv_shape = [1]
    for dtype in [np.float16, np.float32, np.int32]:
        x = np.random.uniform(1, 10,shape).astype(dtype) 
        min_value = np.ones(vv_shape).astype(dtype) * 2
        max_value = np.ones(vv_shape).astype(dtype) * 5
        output = np.zeros(shape, dtype=dtype)
        
        golden = tf.clip_by_value(x, min_value, max_value)
        print("xxxxxxxxxxxxx")
        golden = golden.numpy()

        func([x, min_value, max_value, output], [-1])
        # print(min_value)
        # print(max_value)
        # print(x[-10:])
        print("output", output[-10:])
        print("golden", golden[-10:])
        if verify_result(output, golden):
            print(dtype, "成功")
        else:
            print((output == golden).sum())
            print(dtype, "失败")
        print("----------------------------")


if __name__ == "__main__":
    main()
